package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.EnclosureAlert;
import com.ruoyi.system.mapper.EnclosureAlertMapper;
import com.ruoyi.system.service.EnclosureAlertService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 *  报警推送表(EnclosureAlert)表服务实现类
 *
 * @author makejava
 * @since 2023-03-27 17:57:53
 */
@Service("enclosureAlertService")
public class EnclosureAlertServiceImpl implements EnclosureAlertService {
    @Resource
    private EnclosureAlertMapper enclosureAlertMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public EnclosureAlert queryById(Integer id) {
        return this.enclosureAlertMapper.selectEnclosureAlertById(id);
    }

    /**
     * 分页查询
     *
     * @param enclosureAlert 筛选条件
     * @return 查询结果
     */
    @Override
    public List<EnclosureAlert> queryByPage(EnclosureAlert enclosureAlert) {
        return this.enclosureAlertMapper.selectEnclosureAlertList(enclosureAlert);
    }

    /**
     * 新增数据
     *
     * @param enclosureAlert 实例对象
     * @return 实例对象
     */
    @Override
    public EnclosureAlert insert(EnclosureAlert enclosureAlert) {
        enclosureAlert.setCreatedBy("系统管理员");
        enclosureAlert.setCreatedTime(new Date());
        enclosureAlert.setUpdateBy("系统管理员");
        enclosureAlert.setUpdateTime(new Date());
        this.enclosureAlertMapper.insertEnclosureAlert(enclosureAlert);
        return enclosureAlert;
    }

    /**
     * 修改数据
     *
     * @param enclosureAlert 实例对象
     * @return 实例对象
     */
    @Override
    public EnclosureAlert update(EnclosureAlert enclosureAlert) {
        enclosureAlert.setUpdateBy("系统管理员");
        enclosureAlert.setUpdateTime(new Date());
        this.enclosureAlertMapper.updateEnclosureAlert(enclosureAlert);
        return this.queryById(enclosureAlert.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.enclosureAlertMapper.deleteEnclosureAlertById(id) > 0;
    }
}
